﻿using AspDotNet.Framework.CommonLibs;
using System.Linq;
using System.Reflection;
using System.Web.Mvc;

namespace AspDotNet.Framework.Mvc.FirstDemo.Controllers
{
    public class BaseController : Controller
    {
        public virtual void Index()
        {
            ShowAllUrls();
        }

        protected void ShowAllUrls()
        {
            var methods = this.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public);
            var methodNames = methods.Select(m => m.Name).ToList();

            var urls = methods.Where(m => m.ReturnType.HasParent<ActionResult>())
                .Select(p => $"<div><a href='{Request.Url.Scheme}://{Request.Url.Host}:{Request.Url.Port}/{Request.RequestContext.RouteData.Values.First().Value}/{p.Name}' target='_blank'>{p.Name}</a></div>")
                .ToList();

            Response.Write(string.Join("", urls));
        }
    }
}